import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import dayjs from "dayjs";
import {defHttp} from "@/utils/http/axios";
import {optionsListApi} from "@/api/demo/select";
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '项目名称',
    align:"center",
    dataIndex: 'name',
    width:180,
    resizable: true,
    ellipsis:true
   },
   {
    title: '项目编码',
    align:"center",
    dataIndex: 'code',
    width:180,
    resizable: true,
    ellipsis:true
   },
   {
    title: '负责人',
    align:"center",
    dataIndex: 'chargeBy_dictText',
    width:100,
    resizable: true,
    ellipsis:true
   },
   {
    title: '进度',
    align:"center",
    dataIndex: 'progress',
    customRender:({text})=>{
      return render.renderProcess((text))
    }
   },

   {
    title: '计划开始时间',
    align:"center",
    width:110,
    dataIndex: 'planBeginTime',
    customRender:({text}) =>{
      text = !text ? "" : (text.length > 10 ? text.substr(0,10) : text);
      return text;
    },
   },
   {
    title: '计划完成时间',
    align:"center",
    width:110,
    dataIndex: 'planEndTime',
    customRender:({text}) =>{
      text = !text ? "" : (text.length > 10 ? text.substr(0,10) : text);
      return text;
    },
   },
   {
    title: '实际开始时间',
    align:"center",
    dataIndex: 'factBeginTime',
    defaultHidden:true,
    customRender:({text}) =>{
      text = !text ? "" : (text.length > 10 ? text.substr(0,10) : text);
      return text;
    },
   },
   {
    title: '实际完成时间',
    align:"center",
    dataIndex: 'factEndTime',
    defaultHidden:true,
    customRender:({text}) =>{
      text = !text ? "" : (text.length > 10 ? text.substr(0,10) : text);
      return text;
    },
   },
   {
    title: '项目类型',
    align:"center",
    width:100,
    dataIndex: 'type_dictText'
   },
   {
    title: '联系方式',
    align:"center",
    dataIndex: 'phone',
    defaultHidden:true
   },
   {
     title:'部门',
     align:'center',
     width:100,
     dataIndex:'sysOrgCode_dictText'
   },
   {
    title: '状态',
    width:100,
    align:"center",
    fixed:'right',
    dataIndex: 'status_dictText'
   },
   {
    title: '项目地址',
    align:"center",
    dataIndex: 'address'
   },
   {
    title: '备注',
    align:"center",
    dataIndex: 'remark'
   },
];

export const outListCols: BasicColumn[] = [
   {
    title: '项目名称',
    align:"center",
    dataIndex: 'projectName'
   },
  {
    title: '项目合同号',
    align:"center",
    dataIndex: 'wmContractId'
   },
  {
    title: '计划号',
    align:"center",
    dataIndex: 'wmTaskbookId'
   },
  {
    title: '发出仓库',
    align:"center",
    dataIndex: 'warehouseName'
   },
  {
    title: '物料编码',
    align:"center",
    dataIndex: 'productCode'
   },
  {
    title: '物料名称',
    align:"center",
    dataIndex: 'productName'
   },
  {
    title: '规格',
    align:"center",
    dataIndex: 'specification'
   },
  {
    title: '单位',
    align:"center",
    dataIndex: 'unitOfMeasure'
   },
  {
    title: '发货数量',
    align:"center",
    dataIndex: 'quantity'
   },
  {
    title: '部门',
    align:"center",
    dataIndex: 'buName'
   },
  {
    title: '是否执行完成',
    align:"center",
    dataIndex: 'isOver',
    customRender:({text})=>{
      return text?'是':'否'
    }
   }
  ]

//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '项目名称',
    field: 'name',
    component: 'Input'
  },
  {
    label: '项目类型',
    field: 'type',
    component: 'JDictSelectTag',
    componentProps:{
      dictCode:"project_type"
    }
  },
  {
    label: '部门',
    field: 'sysOrgCode',
    component: 'ApiSelect',
    componentProps: {
      api: () => defHttp.get({ url: '/sys/sysDepart/listAll',params:{isBu:'Y'} }),
      //数值转成String
      numberToString: false,
      //标题字段
      labelField: 'departName',
      //值字段
      valueField: 'orgCode',
      //请求参数
      params: {},
      //返回结果字段
      resultField: 'result',
    },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '项目名称',
    field: 'name',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入项目名称!'},
          ];
     },
  },
  {
    label: '项目编码',
    field: 'code',
    component: 'Input',
    componentProps:{
      placeholder:'不输入则自动生成'
    }
  },
  {
    label: '计划开始时间',
    field: 'planBeginTime',
    component: 'DatePicker',
    defaultValue:dayjs(new Date()).format('YYYY-MM-DD'),
    componentProps: {
      showToday:true,
      format:'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD'
    },
  },
  {
    label: '计划完成时间',
    field: 'planEndTime',
    component: 'DatePicker',
    componentProps: {
      showToday:true,
      format:'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD'
    },
  },
  {
    label: '项目地址',
    field: 'address',
    component: 'Input',
  },
  {
    label: '项目类型',
    field: 'type',
    component: 'JDictSelectTag',
    defaultValue: "SELF",
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入项目类型!'},
          ];
     },
    componentProps:{
      dictCode:"project_type"
    }
  },
  {
    label: '负责人',
    field: 'chargeBy',
    component: 'UserSelect',
    componentProps: {
      //是否多选
      multi: false,
      //从用户表中选择一列，其值作为该控件的存储值，默认id列
      store: 'id',
      //是否排除我自己(当前登录用户)
      izExcludeMy: false,
      //是否禁用
      disabled: false,
    },
  },
  {
    label: '联系方式',
    field: 'phone',
    component: 'Input',
  },
  {
    label: '附件(多选)',
    field: 'file',
    component: 'JUpload',
    componentProps:{
     },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

// 高级查询数据
export const superQuerySchema = {
  name: {title: '项目名称',order: 0,view: 'text', type: 'string',},
  code: {title: '项目编码',order: 1,view: 'text', type: 'string',},
  chargeBy: {title: '负责人',order: 2,view: 'text', type: 'string',},
  progress: {title: '进度',order: 3,view: 'text', type: 'string',},
  status: {title: '状态',order: 4,view: 'list', type: 'string',dictCode: 'project_status',},
  planBeginTime: {title: '计划开始时间',order: 5,view: 'date', type: 'string',},
  planEndTime: {title: '计划完成时间',order: 6,view: 'date', type: 'string',},
  factBeginTime: {title: '实际开始时间',order: 7,view: 'date', type: 'string',},
  factEndTime: {title: '实际完成时间',order: 8,view: 'date', type: 'string',},
  address: {title: '项目地址',order: 9,view: 'text', type: 'string',},
  type: {title: '项目类型',order: 10,view: 'text', type: 'string',},
  phone: {title: '联系方式',order: 11,view: 'text', type: 'string',},
  file: {title: '附件',order: 12,view: 'file', type: 'string',},
  remark: {title: '备注',order: 13,view: 'textarea', type: 'string',},
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
